<?php

namespace app\vpn\admin;

use app\admin\controller\Admin;
use app\user\model\User as UserModel;
use think\facade\Env;
use think\Db;

/**
 * 支付首页控制器
 */
class Index extends Admin
{

    protected function initialize()
    {
        parent::initialize();

        $info = UserModel::where(['id' => session('user_auth.uid')])->find();
        // 给支付做下权限判断
        $this->merchant_id = $info['merchant_id'] ? $info['merchant_id'] : 12345678;
        $this->role = $info['role'] ? $info['role'] : 100;
        $this->have_auth = 1;
        $this->auth_role = 12;
        $this->no_auth = $this->role > $this->auth_role ? true : false;
        $this->uid = $info['id'] ? $info['id'] : 12345678;

        $this->merchant_info = Db::name('payment_merchant_config')->where(['id' => $this->merchant_id])->find();
        $this->manage_merchant = $this->merchant_info['manage_merchant'] ? json_decode($this->merchant_info['manage_merchant'], true) : '';

        $this->is_agent = false;
        if ($this->merchant_info['agent_status'] == 1 && in_array($this->role, ['13', '14', '15'])) {
            $this->is_agent = true;
        }

        // 文件夹路径(下载)
        $this->file_path = Env::get('root_path') . 'data' . DIRECTORY_SEPARATOR . 'download' . DIRECTORY_SEPARATOR;

        // 安全配置

        // 增加
        $this->add_safe = 1;
        // 编辑
        $this->edit_safe = 1;
        // 查看
        $this->see_safe = 1;
        // 删除
        $this->delete_safe = 1;
        // 模拟支付通知
        $this->simulation_pay_notify_safe = 0;
        // 模拟代付通知
        $this->simulation_paid_notify_safe = 0;
        // 模拟退款通知
        $this->simulation_refund_notify_safe = 0;
        // 手动代付
        $this->manual_paid_safe = 0;
        // 手动退款
        $this->manual_refund_safe = 0;
        // 手动批量退款
        $this->manual_batch_refund_safe = 0;
        // 验证码权限
        $this->verificationcode_auth = 1;
        // 密钥查看
        $this->key_see_safe = 0;
        // 系统安全密码
        $this->system_safe_pwd = '';


        // 记录后台日志
        $data_log = $this->request->post();
        if ($data_log) {
            if (isset($data_log['status'])) {
                //unset($data_log['status']);
            }
            $operate_log['url'] = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action();
            $operate_log['uid'] = $info['id'];
            $operate_log['remark'] = json_encode($data_log);
            $operate_log['status'] = 0;
            $operate_log['create_time'] = time();
            Db::name('vpn_operate_log')->insert($operate_log);
        }
    }

    /**
     * 首页
     * @return mixed
     */
    public function index()
    {
        $this->redirect('vpn/order/index');
    }
}
